package com.bailan.foreat.mapper;

import com.bailan.foreat.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ste
 * @since 2023-02-21 07:50:43
 */
@Mapper
public interface ProductMapper extends BaseMapper<Product> {
    //更新库存量
    @Update("update t_product set stock_count=stock_count-#{buyCount} where id=#{productId} and stock_count >= #{buyCount}")
    int updateProductStockCount(Integer productId,Integer buyCount);

    //更新购买量
    @Update("update t_product set buy_count=buy_count+#{buyCount} where id=#{productId}")
    int updateBuyCount(Integer productId,Integer buyCount);

    List<Product> selectAllProducts();
}
